package controller

import (
	"AccessAdmin/api/backend"
	"AccessAdmin/internal/model"
	"AccessAdmin/internal/service"
	"context"
)

// LoginLog 登录日志
var LoginLog = cLoginLog{}

type cLoginLog struct{}

// ShowIndex 登录日志列表
func (c *cLoginLog) ShowIndex(ctx context.Context, req *backend.LoginLogIndexReq) (res *backend.LoginLogIndexRes, err error) {
	service.View().Render(ctx, model.View{
		Title: "登录日志",
	})
	return
}

// IndexData 获取登录日志列表
func (c *cLoginLog) IndexData(ctx context.Context, req *backend.LoginLogIndexListReq) (res *backend.LoginLogIndexListRes, err error) {
	res = &backend.LoginLogIndexListRes{}
	_data, err := service.LoginLog().GetList(ctx, model.LoginLogGetListInput{
		Page:     req.Page,
		Size:     req.Limit,
		Username: req.Username,
	})
	if _data != nil && err == nil {
		res.Data = _data.List
		res.Count = _data.Total
	}
	return
}
